Java Programming Student Courses

This programming assignment is designed to evaluate your knowledge, comprehension and application of some Java programming constructs – if-else, while, boolean and char data types, the null value and == operator. Input from the keyboard and output to a file will be covered. String comparison and conversion of a String object to an int value using the Integer "wrapper" class will be utilized. Multiple classes in a program and the concept of public and private access levels will be explored. It is expected that a program can be written that compiles and runs correctly. You should work on this programming assignment on your own. However, collaboration with others on general logic flow, techniques and Java Core API methods available may be useful. It is most beneficial if you do not share code.

Assignment:

Write a Java program to model a student course’s record and displays the student information. The program should prompt the user for student and course information for two students each with two courses and then output the students course information to a file.

Sample keyboard input text values:

Please enter the student name: John Smith

Please enter the student SSN: 111223333

Please enter the student gender? (m/f): M

Is he/she a full time student? (y/n): N

Please enter the information for the student's 1st course:
Please enter the course id: CIS3020

Please enter the course name : Introduction to CIS

Please enter the course credits [0..5]: 3

Please enter the course grade points [0.0 .. 4.0]: 3.2

Please enter the information for the student's 2nd course:
Please enter the course id: EUH3600

Please enter the course name : European History I

Please enter the course credits [0..5]: 3

Please enter the course grade points [0.0 .. 4.0]: 3.0

Please enter the student name: Mary Smith

Please enter the student SSN: 999887777

Please enter the student gender? (m/f): F

Is he/she a full time student? (y/n): Y

Please enter the information for the student's 1st course:
Please enter the course id: ACC2022

Please enter the course name : Accounting II

Please enter the course credits [0..5]: 4

Please enter the course grade points [0.0 .. 4.0]: 4.0

Please enter the information for the student's 2nd course:
Please enter the course id: MAR3010

Please enter the course name : Marketing Principles

Please enter the course credits [0..5]: 3

Please enter the course grade points [0.0 .. 4.0]: 2.5

Sample output during a particular running of the program:

Name: John Smith

SSN: 111223333

Gender: Male

Part time

Course name: Introduction to CIS
Course ID: CIS3020
Credits: 3
Grade Points: 3.2

Course name: European History I
Course ID: EUH3600
Credits: 3

Grade Points: 3.0

GPA: 3.10 Letter Grade: B

Total Number of Credits: 6 ******

 

Name: Mary Smith
SSN: 999887777
Gender: Female
Full time

Course name: Accounting II
Course ID: ACC2022
Credits: 4

Grade Points: 4.0
Course name: Marketing Principles
Course ID: MAR3010
Credits: 3

Grade Points: 2.5

GPA: 3.35 Letter Grade: B

Total Number of Credits: 7 *******

 

Program:

To implement it, you need to create three classes, Student, Course and Ex6. Each of these classes should be in the same source code file named Ex6.

The class Course should have the following four private instance variables:

The class Course should also have two constructors:

The class Course should also have four public methods:

Use the readLine() method of the BufferedReader class to get the input String. Issue the following prompts to the user:

Before the next prompts is issued the program should read the entered value and assign it to the corresponding instance variable.

Note, that the method readLine() of the BufferedReader class always returns a String object. When the program reads the course credits, it must convert the String object to an int value, and then assign this int value to the instance variable credits. Method parseInt() of class Integer (which is a predefined Java class) converts a String object to an int value.

In the reading the number of credits step you must check if the entered value for credits is a valid one (between 0 and 5). Create a while loop to check the value and repeat this loop until the user enters a valid number.

You must check whether the information entered for the gradePoints is within the valid range, if not, you should keep prompting until the user gives a valid entry. The input string must be converted to a double.

The class Student should have the following six private instance variables:

The class Student must have two constructors:

The class Student should also have two private methods:

To calculate the GPA you will need to do the following:

The class Student must have the following two public methods:

If 3.5 <= GPA <= 4.0, the letter grade is A

If 3.0 <= GPA < 3.5, the letter grade is B

If 2.5 <= GPA < 3.0, the letter grade is C

If 2.0 <= GPA < 2.5, the letter grade is D

If GPA < 2.0, the letter grade is E

For example, if the GPA was 3.65, then the output will be:

GPA: 3.65 Letter Grade: A

	Total Number of Credits: 8 ********

To display the star sequence use a while loop.

Use the readLine() method of the BufferedReader class to get the input String. Issue the following prompts to the user:

The legal input options for the gender are: "m", "M", "f", "F". The prompting must be repeated until the user input is legal.

Use while statement to control the re-input process.

Use the method equals() from the String class to compare the input String with the legal options. The equals() method returns a value of type boolean. Note, that in Java "f" (in double quotes) is considered a String, while 'f' (in single quotes) is a char. Your program should compare the input String with another String (String "f" for example). The instance variable gender is of type char. The input String must be converted to a char value. Use the method charAt() of the String class to do that as follows:
gender = g.charAt(0);
where g is an input String.

The legal input options for the question "Is he/she a full time student?" are : "y", "Y", "n", "N". The prompting must be repeated until the user input is legal.

Create two new Course objects, using the constructor taking no parameters and assign these two objects to course1 and course2 instance variables, repectively. Call the method readCourseInfo() to read the course information of course1 and course2


The main method in the class Ex6 should do the following:



// Example of keybaord & file IO and the use of the Integer "wrapper" class

class Example
{
public static void main( String[] args ) throws Exception
{
// create a BufferedReader stream, which is bound
// to the standard input stream

BufferedReader br = new BufferedReader
(new InputStreamReader(System.in));

System.out.print( "Please enter your name:" );

// read a String from the keyboard
String name = br.readLine();

System.out.print( "Please enter your age:" );

// read another String from the keyboard
String ageStr = br.readLine();

// convert the String age into a int value
int age = Integer.parseInt(ageStr);

// open a file and create a PrintStream connected to this file
PrintStream pr = new PrintStream
(new FileOutputStream (new File ("myfile")));

// write into file
pr.println( "Name:" + name);
pr.println( "Age:" + age);
}
}

 

The name of the object must be Ex6. To run the program, the Ex6 Java object is invoked. The Ex6 skeleton source code is presented below and should be used. This source code should be put in a file named Ex6.java and then compiled. When it is compiled the object that is run will be called Ex6.class.

IMPORTANT: The file for this program must be named Ex6.java. (Not EX06, ex6, or any other variation). Your file must be should placed in a subdirectory for this project. I suggest something like C:\javacode\Ex6\